<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<link rel="stylesheet" href="./jeDate/skin/jedate.css">
	<style>
		.illegalBuildingAnalysisDate{
		    display:flex;
			height: 1000px;
		}
		.illegalBuildingAnalysisDate input{
		    width:100px;
		    height: 30px;
		    background:rgba(255,255,255,1);
		    border-radius:4px;
		    border:1px solid rgba(217,217,217,1);
		    padding-left:10px;
		    padding-right:25px;
		}
		.illegalBuildingAnalysisDate >span{
		 margin:0px 10px;
		 line-height: 30px;
		}
		.illegalBuildingAnalysisDate .illegalBuildingAnalysisF:after,
		.illegalBuildingAnalysisDate .illegalBuildingAnalysisL:after{
		    content:'';
		    position:absolute;
		    right:5px;
		    top:8px;
		    width:15px;
		    height: 15px;
		    display: inline-block;
		    background: url(./images/date.png);
		    background-size: 100% 100%;
		}
		.illegalBuildingAnalysisDate >button{
		    width:56px;
		    height:30px;
		    background:rgba(61,110,248,1);
		    border-radius:3px;
		    border:0;
		    outline:none;
		    margin-left:30px;
		    font-size:12px;
		    font-family:MicrosoftYaHei;
		    color:rgba(255,254,254,1);
		    line-height:12px;
		}
		.illegalBuildingAnalysisF,.illegalBuildingAnalysisL{
		    position:relative;
		}
		.illegalBuildingAnalysisDate > .dateLoo{
		font-size:14px;
		font-family:PingFangSC-Regular;
		font-weight:400;
		color:rgba(102,102,102,1);
		line-height: 30px;
		}
	</style>
	<body>
		<div class="illegalBuildingAnalysisDate">
			<span class='dateLoo'>统计区间</span>
			<div class="illegalBuildingAnalysisF" id='AnalysisF'><input type="text" id="test1" placeholder="请选择开始时间"
				 autocomplete="off"></div><span>-</span>
			<div class="illegalBuildingAnalysisL" id='AnalysisL'><input type="text" id="test2" placeholder="请选择开始时间"
				 autocomplete="off"></div>
			<button>查询</button>
		</div>
	</body>
	<script src="jeDate/jedate.min.js"></script>
	<script>
		window.onload = function() {
			var myDate = new Date();
			let year = myDate.getFullYear();
			let month = myDate.getMonth() >= 10 ? myDate.getMonth() : '0' + myDate.getMonth();
			// let month=myDate.getMonth();
			if (month == 0) {
				var ym2 = (year - 1) + ' 年 ' + (12) + ' 月';
			} else {
				var ym2 = year + ' 年 ' + (month) + ' 月';
			}
			var mon = (12 - (12 - month) + 1) >= 10 ? (12 - (12 - month) + 1) : '0' + (12 - (12 - month) + 1);
			let ym1 = year - 1 + ' 年 ' + mon + ' 月';

			jeDate("#test2", {
				theme: {
					bgcolor: "#00A1CB",
					color: "#ffffff",
					pnColor: "#00CCFF"
				},
				isinitVal: true,
				initDate: [{
					YYYY: year,
					MM: month
				}, false],
				format: "YYYY-MM",
				isToday: false,
				maxDate: year + '-' + month,
				donefun: function(obj) {
					// console.log(obj);
					let years = obj.date[0].YYYY;
					let months = obj.date[0].MM;
					console.log(months);
					var maxStr = years + '-' + months + '-31';
					if (months == 12) {

						var minStr = (years) + '-' + '01-01';
					} else {
						var mon = (12 - (12 - months) + 1) >= 10 ? (12 - (12 - months) + 1) : '0' + (12 - (12 - months) + 1);
						var minStr = (years - 1) + '-' + (mon) + '-01';
					}
					var idObject = document.getElementById('test1');
					if (idObject != null)
						idObject.parentNode.removeChild(idObject);
					var input = document.createElement('input'); //创建input节点
					input.setAttribute('type', 'text'); //定义类型是文本输入
					input.setAttribute('id', 'test1');
					input.setAttribute('placeholder', '请选择开始时间');
					input.setAttribute('autocomplete', 'off');
					document.getElementsByClassName('illegalBuildingAnalysisF')[0].appendChild(input);
					// document.getElementById('AnalysisF').appendChild(input);
					jeDate("#test1", {
						theme: {
							bgcolor: "#00A1CB",
							color: "#ffffff",
							pnColor: "#00CCFF"
						},
						format: "YYYY-MM",
						isToday: false,
						maxDate: maxStr,
						minDate: minStr
					})
				}, //点击确定后的回调函数
			});
			jeDate("#test1", {
				theme: {
					bgcolor: "#00A1CB",
					color: "#ffffff",
					pnColor: "#00CCFF"
				},
				isinitVal: true,
				initDate: [{
					YYYY: year - 1,
					MM: mon
				}, false],
				format: "YYYY-MM",
				isToday: false,
				maxDate: year + '-' + month,
				donefun: function(obj) {
					let years = obj.date[0].YYYY;
					let months = obj.date[0].MM;
					var Mix = years + '-' + (months) + '-01';
					if (months == 1) {
						var y = years;
						var m = 12;
						var Max = y + '-' + m + '-31';
					} else {
						var y = years + 1;
						var m = (12 - (12 - months) - 1) >= 10 ? (12 - (12 - months) - 1) : '0' + (12 - (12 - months) - 1);
						var Max = y + '-' + m + '-31';
					}

					if (y > year) {
						var MaxF = new Date().getFullYear() + '-' + (new Date().getMonth()) + '-' + new Date().getDate();
					} else if ((m > month) && (y == year)) {
						var MaxF = new Date().getFullYear() + '-' + (new Date().getMonth()) + '-' + new Date().getDate();
					} else {
						var MaxF = Max;
					}
					var idObject = document.getElementById('test2');
					if (idObject != null)
						idObject.parentNode.removeChild(idObject);
					var input = document.createElement('input'); //创建input节点
					input.setAttribute('type', 'text'); //定义类型是文本输入
					input.setAttribute('id', 'test2');
					input.setAttribute('placeholder', '请选择开始时间');
					input.setAttribute('autocomplete', 'off');
					document.getElementsByClassName('illegalBuildingAnalysisL')[0].appendChild(input);
					// document.getElementById('AnalysisL').appendChild(input);

					jeDate("#test2", {
						theme: {
							bgcolor: "#00A1CB",
							color: "#ffffff",
							pnColor: "#00CCFF"
						},
						format: "YYYY-MM",
						isToday: false,
						maxDate: MaxF,
						minDate: Mix
					})
				}, //点击确定后的回调函数
			});
		}
	</script>
</html>
